package com.goods.controller;

import com.goods.model.ResponseData;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 接口基类
 * @author huangyanzhong
 * @date 2020-04-01
 */
public class BaseController {

    /**
     *
     * @param binder
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }


    /**
     * 成功响应
     * @return
     */
    protected ResponseData successResponse(){
        return new ResponseData(true,"操作成功",null);
    }

    /**
     * 成功响应
     * @return
     */
    protected ResponseData successResponse(Object data){
        return new ResponseData(true,"操作成功",data);
    }

    /**
     * 失败响应
     * @return
     */
    protected ResponseData failureResponse(String message){
        return new ResponseData(false,message,"");
    }


}
